// 使用正则表达式进行匹配
// "[00:22.29]都 是勇敢的"
const timeRegExp = /\[(\d{2}):(\d{2})\.(\d{2,3})\]/ 

export function parseLyric(lyricString) {
	if(!lyricString) return
	const lyricStrings = lyricString.split('\n')
	const lyricInfos = []
	lyricStrings.forEach(lineString => {
		const timeResult = timeRegExp.exec(lineString)
		if(!timeResult) return
		// 获取时间
		const minute = timeResult[1] * 60 * 1000
		const second = timeResult[2] * 1000
		let millsecond = timeResult[3]
		millsecond = millsecond.length === 2 ? millsecond * 10 : millsecond * 1
		const time = minute + second + millsecond
		
		// 获取文字
		const text = lineString.split(']')[1]
		lyricInfos.push({ time, text })
	})
	return lyricInfos
}